/**
 * 
 */
package edu.umd.clip.lm.model.decoding;

import edu.umd.clip.lm.model.*;
import java.util.*;
/**
 * @author Denis Filimonov <den@cs.umd.edu>
 *
 */
public class ClusterId implements Cloneable {
	private int clusterIds[];
	
	public ClusterId() {
		clusterIds = new int[Experiment.getInstance().getNumLMs()];
		Arrays.fill(clusterIds, -1);
	}
	
	private ClusterId(int clusterIds[]) {
		this.clusterIds = clusterIds;
	}
	
	public int getId(int modelNum) {
		return clusterIds[modelNum];
	}
	
	public void setId(int modelNum, int clusterid) {
		clusterIds[modelNum] = clusterid;
	}

	@Override
	public Object clone() {
		return new ClusterId(Arrays.copyOf(clusterIds, clusterIds.length));
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof ClusterId) {
			return Arrays.equals(clusterIds, ((ClusterId)obj).clusterIds);
		}
		return false;
	}

	@Override
	public int hashCode() {
		return Arrays.hashCode(clusterIds);
	}

	@Override
	public String toString() {
		return Arrays.toString(clusterIds);
	}
	
	public boolean isEmpty() {
		for(int id : clusterIds) {
			if (id != -1) return false;
		}
		return true;
	}
	
	public int getFirstNonEmptyLmId() {
		for(int i=0; i<clusterIds.length; ++i) {
			if (clusterIds[i] > 0) return i;
		}
		return -1;
	}
}
